package logic

import (
	"class/classrpc/classrpc"
	"class/classrpc/internal/svc"
	"class/models"
	"context"
	"fmt"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectDelLogic {
	return &CollectDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 取消收藏
func (l *CollectDelLogic) CollectDel(in *classrpc.CollectDelRequest) (*classrpc.CollectDelResponse, error) {
	// todo: add your logic here and delete this line

	var collect models.Collection
	models.DB.Debug().Where("id = ?", in.CollectId).Find(&collect)
	if collect.ID == 0 {
		return nil, fmt.Errorf("该物品不存在")
	}

	models.DB.Debug().Delete(&collect)

	return &classrpc.CollectDelResponse{}, nil
}
